package com.dtruth.hadoop.hdfs2hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

public class Hdfs2HBaseMain {
	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		/*
		 * String[] otherArgs = new GenericOptionsParser(conf,
		 * args).getRemainingArgs(); if (otherArgs.length != 2) {
		 * System.err.println("Usage: wordcount <infile> <table>");
		 * System.exit(2); }
		 */
		conf.set("fs.defaultFS", "hdfs://land:9000/");
		//conf.set("mapreduce.framework.name", "yarn");
		conf.set("mapred.job.tracker", "land:9001");
		conf.set("hbase.zookeeper.quorum", "math");
		conf.set("hbase.zookeeper.property.clientPort", "2181");
		conf.set("hbase.master", "math:60000");
		Job job = Job.getInstance(conf, "file2hbase");
		job.setJarByClass(Hdfs2HBaseMain.class);
		job.setMapperClass(Hdfs2HBaseMapper.class);
		job.setReducerClass(Hdfs2HBaseReducer.class);
		job.setOutputKeyClass(ImmutableBytesWritable.class);
		job.setOutputValueClass(Put.class);
		job.setOutputFormatClass(TableOutputFormat.class);
		FileInputFormat.addInputPath(job, new Path("hdfs://land:9000/mrproject/test/data.txt"));
		job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, "mytest");

		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}